﻿// This code is released under the BSD license.
namespace PugLib.TestCollateral
{
    using System;
    using System.Globalization;
    using System.Net;
    using IO;
    using Math;

    /// <summary>
    /// just a demo class 
    /// </summary>    
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1036:OverrideMethodsOnComparableTypes")]
    public class Computer : IComparable
    {
        public string Domain { get; set; }
        public string Name { get; set; }
        public string OperatingSystem { get; set; }
        public DateTime? BootDate { get; set; }
        public IPAddress IPAddress { get; set; }
        public short? Number { get; set; }
        public CultureInfo Language { get; set; }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            Computer other = obj as Computer;
            if (other == null)
            {
                return -1;
            }
            return string.CompareOrdinal(Name, other.Name);
        }

        #endregion

        public override string ToString()
        {
            return string.Format(CultureInfo.InvariantCulture, "{0}\\{1}, {2}, {3}", Domain, Name, IPAddress, OperatingSystem);
        }

        public bool IsAServer()
        {
            return !string.IsNullOrEmpty(OperatingSystem) &&
                   OperatingSystem.ToUpperInvariant().Contains("SERVER");
        }

        public static Computer CreateRandom()
        {
            return new Computer
                       {
                           Domain = Files.CreateFileGuid(),
                           Name = Files.CreateFileGuid(),
                           OperatingSystem = Files.CreateFileGuid(),
                           BootDate = DateTime.UtcNow.AddDays(-1.0 * PugRandom.GetRandomInRange(1, 800)),
                           IPAddress = new IPAddress(PugRandom.GetRandomInRange(0, Int32.MaxValue)),
                           Number = (short)PugRandom.GetRandomInRange(0, 8000),
                           Language = CultureInfo.CurrentCulture
                       };
        }
    }
}